package com.queen.testretrofitrxjava.ui.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.queen.testretrofitrxjava.R;
import com.queen.testretrofitrxjava.entity.Subject;
import com.queen.testretrofitrxjava.httpSubscriber.SubscriberOnNextListener;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by liukun on 16/3/12.
 */
public class RetrofitRxjavaFragment extends Fragment {

    public static final String TAG = RetrofitRxjavaFragment.class.getSimpleName();

    @Bind(R.id.click_me_BN)
    Button clickMeBN;
    @Bind(R.id.result_TV)
    TextView resultTV;

    private SubscriberOnNextListener onNextListener;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_retrofit_rxjava, container, false);
        ButterKnife.bind(this, view);

        onNextListener = new SubscriberOnNextListener<List<Subject>>() {
            @Override
            public void onNext(List<Subject> subjects) {
                resultTV.setText("subjects.size() = " + subjects.size());
            }
        };

        return view;
    }

    @OnClick(R.id.click_me_BN)
    public void onClick() {
        getMovie();
    }

    private void getMovie(){
//        HttpMethods.getInstance().getTopMovie(new ProgressSubscriber(onNextListener), 0, 10);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}